The filled blanks are seen below.
null
In this example, any slot of the array might reference a String so all slots must be visited. To make the output look nice, slots that contain null are handled differently that those that refer to Strings.
String[] strArray = new String[8] ; // combined statement . . . . . for (int j=0; j < strArray.length; j++ ) { if ( strArray[j] != null ) System.out.println( "Slot " + j + ": " + strArray[j] ); else System.out.println( "Slot " + j + ": " + "empty" ); }
(Actually, println()
will print "null" when given
a null
reference, so the if
statement is not really required.
But with some methods things will go horribly wrong if you them
a null
.)